package com.yonyou.crm.bpub.template.service;

import java.util.ArrayList;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.bpub.template.entity.TemplatesBodyVO;
import com.yonyou.crm.bpub.template.entity.TemplatesFilterVO;
import com.yonyou.crm.bpub.template.entity.TemplatesHeaderVO;
import com.yonyou.crm.bpub.template.entity.TemplatesTriggerVO;
import com.yonyou.crm.bpub.template.entity.TemplatesVO;

@Service
public class TemplatesBizServiceImpl {
	
	@Autowired
	CustomerTemplates customerTemplateService;
	
	@Autowired
	OpportunityTemplate oppTemplateService;
	
	@Autowired
	ContactTemplates contactService;
	
	@Autowired
	LeadTemplates leadService;
	
	@Autowired
	CumprmtTemplates cumprmtService;
	
	public TemplatesVO getTemplate(Map<String, Object> param){
		String module = String.valueOf(param.get("module"));
		TemplatesVO template = new TemplatesVO();
		BaseTemplates service = null;
		switch(module) {
			case "accounts":
				service = customerTemplateService;
				break;
			case "opportunities":
				service = oppTemplateService;
				break;
			case "contacts":
				service = contactService;
				break;
			case "leads":
				service = leadService;
				break;
			case "cumprmts":
				service = cumprmtService;
				break;
			default:
				//nothing
		}
		ArrayList<TemplatesHeaderVO> header = service.getHeader();
		template.setHeaderlist(header);
		
		ArrayList<TemplatesBodyVO> body = service.getBody();
		template.setBodylist(body);
		
		ArrayList<TemplatesTriggerVO> trigger = service.getTrigger();
		template.setTriggerlist(trigger);
		
		ArrayList<TemplatesFilterVO> filter = service.getFilter();
		template.setFilterlist(filter);
		
		return template;
	}
	
	
}
